$('.text').focus(function(){
    $(this).prop('placeholder','')
}).blur(function(){
   if($(this).val() == ''){
    $(this).prop('placeholder','请输入用户名')
    $('.alertText').css({
        visibility: 'visible'
    })
   }else{
    $('.alertText').css({
        visibility: 'hidden'
    })
   }
})
$('.psd').focus(function(){
    $(this).prop('placeholder','')
}).blur(function(){
   if($(this).val() == ''){
    $(this).prop('placeholder','请输入密码')
    $('.alertPsd').css({
        visibility: 'visible'
    })
   }else{
    $('.alertPsd').css({
        visibility: 'hidden'
    })
   }
})
$('#top .logo').click(function(){
    location.href = '../pages/index.html'
})


$('form').submit(function (e) {
    e.preventDefault()
    if ($('.psd').val() == '' || $('.text').val() == '') {
        if ($('.psd').val() == '' && $('.text').val() == '') {
            alert('登录失败，请填写用户名和密码')
            return
        }
        if ($('.psd').val() == '') {
            alert('登录失败，请填写密码')
            return
        }
        if ($('.text').val() == '') {
            alert('登录失败，请填写用户名')
            return
        }
    }

    axios({
        method: 'post',
        url: 'http://api.yuguoxy.com/api/member/login',
        data: {
            username: $('.text').val(),
            password: $('.psd').val()
        }
    }).then(response => {
        let resultInfo = response.data.resultInfo
        if (response.data.resultCode == 1) {
            alert(`登录成功欢迎你${resultInfo.username}`)
            let user = localStorage.getItem('PERSON')
            user = JSON.parse(user) || []
            let person = {
                username: $('.text').val(),
                password:$('.psd').val(),
            }
            user.unshift(person)
            localStorage.setItem('PERSON',JSON.stringify(user))
            location.href = '../pages/index.html' + '?confrim' + `&username=${$('.text').val()}`
        } else {
            alert(resultInfo)
        }
    })
})
